package logic

import (
	"class_rpc/class"
	"class_rpc/internal/model/mysql"
	"class_rpc/internal/svc"
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCommentLogic {
	return &CreateCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateCommentLogic) CreateComment(in *class.CreateCommentRequest) (*class.CreateCommentResponse, error) {
	// todo: add your logic here and delete this line
	c := mysql.Comment{
		UserId:  int(in.UserId),
		ClassId: int(in.ClassId),
		Comment: in.Comment,
	}
	err := c.CreateComment()
	if err != nil {
		return nil, status.Error(codes.Internal, "添加评论失败")
	}
	return &class.CreateCommentResponse{}, nil
}
